/*
 * Copyright 2012 NJUT  qixiaobo. All rights reserved.
 */
package com.fujitsu.nanjing.mobile.common;

import org.apache.log4j.Logger;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.PropertyUtils;

/**
 * ReflectUtils.java
 * <p>
 * 反射工具类
 * </p>
 * 
 * @since 2012/11/28
 * @author qixb.fnst
 */
public class ReflectUtils extends PropertyUtils {
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(ReflectUtils.class);

    public static void copy(Object src, Object dest)
            throws IllegalAccessException, InvocationTargetException,
            NoSuchMethodException {
        copyProperties(dest, src);
    }

    /**
     * qixib.fnst
     * 
     * @param coreUser
     * @return
     */
    public static <T> List<Param> initParams(Class<T> clazz, T t,
            List<String> unEdit) {
        List<Param> params = new ArrayList<Param>();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (unEdit.contains(field.getName())) {
                continue;
            }
            Param param = new Param();
            param.setText(field.getName());
            try {
                field.setAccessible(true);
                param.setValue(field.get(t));
                param.setDisable("true");
            } catch (IllegalArgumentException e) {
                logger.error(field.getName() + " IllegalArgumentException");
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                logger.error(field.getName() + " IllegalAccessException");
                e.printStackTrace();
            }
            params.add(param);
        }
        return params;
    }
}
